package tool;

import math.Maths;
import util.Color;

public class NoiseGen {
    
    private int[] noisePermuts;
    private int[] noiseColorsBla;
    private int[] noiseColorsWhi;
    private int colorLimit;
    private int nColors;
    
    public NoiseGen(int nPixels, int _colorLimit, int nNoiseColors) {
        colorLimit = _colorLimit;
        if (colorLimit > 255) {
            colorLimit = 255;
        } else if (colorLimit < 0) {
            colorLimit = 0;
        }
        nColors = nNoiseColors;
        noiseColorsBla = new int[nColors];
        noiseColorsWhi = new int[nColors];
        noisePermuts = new int[nPixels];
        for (int i = 0; i < nPixels; i++) {
            noisePermuts[i] = Maths.randomInt(nColors);
        }
    }
    
    public void genNoiseColors() {
        int noiseCompBla;
        int noiseCompWhi;
        for (int i = 0; i < nColors; i++) {
            noiseCompBla = Maths.randomInt(colorLimit);
            noiseCompWhi = 255 - noiseCompBla;
            noiseColorsBla[i] = Color.getColorRGBAi(noiseCompBla, noiseCompBla, noiseCompBla, 255);
            noiseColorsWhi[i] = Color.getColorRGBAi(noiseCompWhi, noiseCompWhi, noiseCompWhi, 255);
        }
    }
    
    public int getBlackNoise(int index) {
        return noiseColorsBla[noisePermuts[index]];
    }
    
    public int getWhiteNoise(int index) {
        return noiseColorsWhi[noisePermuts[index]];
    }
    
}
